package solutions.leetcode.normal

import java.util.PriorityQueue

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/problems/maximal-score-after-applying-k-operations/">2530. 执行 K 次操作后的最大分数</a>
 */
private class Solution2530 {
    fun maxKelements(nums: IntArray, k: Int): Long {
        val queue = PriorityQueue<Int> {o1, o2 -> o2 - o1}
        for (item in nums) {
            queue.offer(item)
        }
        var c = 0L
        var t = k
        while (t-- > 0) {
            val n = queue.poll()
            c += n
            queue.offer(Math.ceil(n.toDouble() / 3).toInt())
        }
        return c
    }
}

fun main() {
    println(Solution2530().maxKelements(
        intArrayOf(
            1,10,3,3,3
        ), 3
    ))
}